package com.classbook.violet.baigiang.fragment;

import java.util.HashMap;
import java.util.List;

import com.classbook.violet.baigiang.singleton.MyApplication;
import com.classbook.violet.baigiang.singleton.MySingleton;
import com.classbook.violet.baigiang.subject.SubjectNode;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

public class MFragmentAdapter extends FragmentPagerAdapter{
	
//	int lop = 6;
	
//	String[] page_title = {"Tổng hợp", "Đại số", "Hình học",
//			"Ngữ văn", "Tiếng Anh", "Vật lí", "Sinh học", "Lịch sử", "Địa lí"};
//	HashMap<String, String> sub_map = new HashMap<String, String>();
	
	private List<SubjectNode> list_subject;

	public MFragmentAdapter(FragmentManager fm) {
		super(fm);
		list_subject = MySingleton.getInstance().mParser.listStudy;
	}

	@Override
	public Fragment getItem(int arg0) {
//		Log.i("GET FRAGMENT", "POSITON = " + arg0);
		// TODO Auto-generated method stub
		Fragment myFragment = new MenuFragment();
		
		if (arg0 == 0){
			return myFragment = new MenuFragment();
		}else{
			for (int i = 1; i < list_subject.size() + 1; i++){
				if (arg0 == i){
					myFragment = new SubjectFragment();
					Bundle mBundle = new Bundle();
					mBundle.putString("name", list_subject.get(i - 1).label);
//					mBundle.putString("link", sub_map.get(page_title[i]));
					myFragment.setArguments(mBundle);
					return myFragment;
				}
			}
		}
		
		return myFragment;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list_subject.size() + 1;
	}
	
	@Override
    public CharSequence getPageTitle(int position) {
        if (position == 0){
        	return "Tổng hợp";
        }else {
        	return list_subject.get(position - 1).label;
        }
    }

}
